﻿using System;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Input;

using EasyORM;
using Tools;

namespace DemoWPF
{
	public class Model : Model<Item> { public Model() : base() { } }
	public class Model<T>
		where T : INotifyPropertyChanged, new()
	{
		public ListCollectionView View { get; private set; }
		public ICommand AddNewCommand { get; private set; }
		public ICommand RemoveCommand { get; private set; }
		
		public Model()
		{
			View = new ListCollectionView(DataStorage.GetSingleCollection<T>());
			
			AddNewCommand = new RelayCommand(p => { View.AddNew(); View.CommitNew(); },
			                                 p => View.CanAddNew);
			
			RemoveCommand = new RelayCommand(p => View.Remove(View.CurrentItem),
			                                 p => View.CanRemove && View.CurrentItem != null);
		}
	}
}
